fun getRandomString(length: Int) : String {
    val charset = ('a'..'z') + ('A'..'Z') + ('0'..'9')

    return List(length) { charset.random() }
        .joinToString("")
}

fun randowStr(num:Int){
    for (i in 0 until num){
        println(getRandomString(16))
    }
}

fun create_appliance_houde(floor_number: Int, room_number: Int, acc: Int):String {
    val appliance_list = listOf("热水壶","电视","空调","电脑","手机","用电设备1","用电设备2","用电设备3")
    var retStr = ""
    appliance_list.forEachIndexed { index, appliance ->
        val appliance_str = "{\"id\":\"LOWVOL-APPLIANCE-${40000+acc+index}\"," +
                "\"name\":\"厚德阁${floor_number}层${room_number}房间第${index+1}个电器设备${appliance}\", " +
                "\"code\": \"APPLIANCE-${getRandomString(16)}\"}"
        retStr += appliance_str + ","
    }
    return retStr.substring(0, retStr.length - 1)
}

fun create_houdege_meta(){
    val floorList = mutableListOf(27, 27, 27, 27, 27)
    var room_acc_num = 1
    var appliance_num = 1
    var roomStr = ""
    floorList.forEachIndexed { index, floor_it ->
        for(i in 0 until floor_it){
            val room_number = (index+1).toString() + String.format("%02d", i+1)
            val json_str = "{\"id\":\"LOWVOL-ROOM-${30000+room_acc_num}\"," +
                    "\"name\":\"厚德阁${index+1}层${room_number}房间\", " +
                    "\"code\": \"ROOM-${getRandomString(16)}\", " +
                    "\"children\": [" + create_appliance_houde(index+1, room_number.toInt(), appliance_num) + "]" +
                    "},"
            room_acc_num++
            appliance_num = appliance_num + 8
            roomStr += json_str
        }
     }
    println(roomStr.substring(0, roomStr.length - 1))
}

fun create_appliance_wendao(floor_number: Int, room_number: Int, acc: Int):String {
    val appliance_list = listOf("热水壶","电视","空调","电脑","手机","烘干机1","烘干机2","熨斗", "洗衣机1", "洗衣机2")
    var retStr = ""
    appliance_list.forEachIndexed { index, appliance ->
        val appliance_str = "{\"id\":\"LOWVOL-APPLIANCE-${40000+acc+index}\"," +
                "\"name\":\"问道阁${floor_number}层${room_number}房间第${index+1}个电器设备${appliance}\", " +
                "\"code\": \"APPLIANCE-${getRandomString(16)}\"}"
        retStr += appliance_str + ","
    }
    return retStr.substring(0, retStr.length - 1)
}


fun create_wendaoge_meta(){
    val floorList = listOf(18,17,17)
    var room_acc_num = 136
    var appliance_num = 1081
    var roomStr = ""
    floorList.forEachIndexed { index, floor_it ->
        for(i in 0 until floor_it){
            val room_number = (index+1).toString() + String.format("%02d", i+1)
            val json_str = "{\"id\":\"LOWVOL-ROOM-${30000+room_acc_num}\"," +
                    "\"name\":\"问道阁${index+1}层${room_number}房间\", " +
                    "\"code\": \"ROOM-${getRandomString(16)}\", " +
                    "\"children\": [" + create_appliance_wendao(index+1, room_number.toInt(), appliance_num) + "]" +
                    "},"
            room_acc_num++
            appliance_num = appliance_num + 10
            roomStr += json_str
        }
    }
    println(roomStr.substring(0, roomStr.length - 1))
}

fun create_appliance_green(floor_number: Int, room_number: Int, acc: Int):String {
    val appliance_list = listOf("立式空调1","立式空调2","专业空调")
    var retStr = ""
    appliance_list.forEachIndexed { index, appliance ->
        val appliance_str = "{\"id\":\"LOWVOL-APPLIANCE-${40000+acc+index}\"," +
                "\"name\":\"绿色楼${floor_number}层${room_number}房间第${index+1}个电器设备${appliance}\", " +
                "\"code\": \"APPLIANCE-${getRandomString(16)}\"}"
        retStr += appliance_str + ","
    }
    return retStr.substring(0, retStr.length - 1)
}

fun create_green_meta(){
    val roomList = listOf("102", "103", "104", "201", "202", "203", "301", "302", "401", "402", "403", "502", "503", "504")
    var room_acc_num = 188
    var appliance_num = 1601
    var roomStr = ""
    roomList.forEachIndexed{ index, room_number ->
        val floor = room_number.substring(0,1)
        val json_str = "{\"id\":\"LOWVOL-ROOM-${30000 + room_acc_num}\"," +
                "\"name\":\"绿色楼${floor}层${room_number}房间\", " +
                "\"code\": \"ROOM-${getRandomString(16)}\", " +
                "\"children\": [" + create_appliance_green(index+1, room_number.toInt(), appliance_num) + "]" +
                "},"
        room_acc_num++
        appliance_num = appliance_num + 3
        roomStr += json_str
    }
    println(roomStr.substring(0, roomStr.length - 1))
}

fun create_appliance_chuangxin(floor_number: Int, room_number: Int, acc: Int):String {
    val appliance_list = listOf("立式空调1","立式空调2","立式空调3","立式空调4","立式空调5")
    var retStr = ""
    appliance_list.forEachIndexed { index, appliance ->
        val appliance_str = "{\"id\":\"LOWVOL-APPLIANCE-${40000+acc+index}\"," +
                "\"name\":\"创新楼${floor_number}层${room_number}房间第${index+1}个电器设备${appliance}\", " +
                "\"code\": \"APPLIANCE-${getRandomString(16)}\"}"
        retStr += appliance_str + ","
    }
    return retStr.substring(0, retStr.length - 1)
}

fun create_chuangxin_meta(){
    val roomList = listOf("101", "102", "103", "201", "202", "203", "301", "302", "401", "402", "501")
    var room_acc_num = 202
    var appliance_num = 1643
    var roomStr = ""
    roomList.forEachIndexed{ index, room_number ->
        val floor = room_number.substring(0,1)
        val json_str = "{\"id\":\"LOWVOL-ROOM-${30000 + room_acc_num}\"," +
                "\"name\":\"创新楼${floor}层${room_number}房间\", " +
                "\"code\": \"ROOM-${getRandomString(16)}\", " +
                "\"children\": [" + create_appliance_chuangxin(floor.toInt(), room_number.toInt(), appliance_num) + "]" +
                "},"
        room_acc_num++
        appliance_num = appliance_num + 5
        roomStr += json_str
    }
    println(roomStr.substring(0, roomStr.length - 1))
}

fun create_appliance_open(floor_number: Int, room_number: Int, acc: Int):String {
    val appliance_list = listOf("立式空调1","立式空调2")
    var retStr = ""
    appliance_list.forEachIndexed { index, appliance ->
        val appliance_str = "{\"id\":\"LOWVOL-APPLIANCE-${40000+acc+index}\"," +
                "\"name\":\"开放楼${floor_number}层${room_number}房间第${index+1}个电器设备${appliance}\", " +
                "\"code\": \"APPLIANCE-${getRandomString(16)}\"}"
        retStr += appliance_str + ","
    }
    return retStr.substring(0, retStr.length - 1)
}

fun create_open_meta(){
    val roomList = listOf("101", "201", "301", "302", "303", "304", "305", "401", "402", "403", "404", "405", "501", "502", "503")
    var room_acc_num = 213
    var appliance_num = 1698
    var roomStr = ""
    roomList.forEachIndexed{ index, room_number ->
        val floor = room_number.substring(0,1)
        val json_str = "{\"id\":\"LOWVOL-ROOM-${30000 + room_acc_num}\"," +
                "\"name\":\"开放楼${floor}层${room_number}房间\", " +
                "\"code\": \"ROOM-${getRandomString(16)}\", " +
                "\"children\": [" + create_appliance_open(floor.toInt(), room_number.toInt(), appliance_num) + "]" +
                "},"
        room_acc_num++
        appliance_num = appliance_num + 2
        roomStr += json_str
    }
    println(roomStr.substring(0, roomStr.length - 1))
}

fun create_appliance_zhiwei(floor_number: Int, room_number: Int, acc: Int):String {
    val appliance_list = listOf("立式空调1","立式空调2","立式空调3")
    var retStr = ""
    appliance_list.forEachIndexed { index, appliance ->
        val appliance_str = "{\"id\":\"LOWVOL-APPLIANCE-${40000+acc+index}\"," +
                "\"name\":\"知味园${floor_number}层${room_number}房间第${index+1}个电器设备${appliance}\", " +
                "\"code\": \"APPLIANCE-${getRandomString(16)}\"}"
        retStr += appliance_str + ","
    }
    return retStr.substring(0, retStr.length - 1)
}

fun create_zhiwei_meta(){
    val roomList = listOf("101", "102", "201", "202", "203", "204", "205")
    var room_acc_num = 228
    var appliance_num = 1728
    var roomStr = ""
    roomList.forEachIndexed{ index, room_number ->
        val floor = room_number.substring(0,1)
        val json_str = "{\"id\":\"LOWVOL-ROOM-${30000 + room_acc_num}\"," +
                "\"name\":\"知味园${floor}层${room_number}房间\", " +
                "\"code\": \"ROOM-${getRandomString(16)}\", " +
                "\"children\": [" + create_appliance_zhiwei(floor.toInt(), room_number.toInt(), appliance_num) + "]" +
                "},"
        room_acc_num++
        appliance_num += 3
        roomStr += json_str
    }
    println(roomStr.substring(0, roomStr.length - 1))
}

fun main(args: Array<String>) {
    println("Hello World!")

    // Try adding program arguments via Run/Debug configuration.
    // Learn more about running applications: https://www.jetbrains.com/help/idea/running-applications.html.
    println("Program arguments: ${args.joinToString()}")

//    println(getRandomString(16))
//    randowStr(27)

//    create_houdege_meta()
//    create_wendaoge_meta()
//    create_green_meta()
//    create_chuangxin_meta()
//    create_open_meta()
//    create_zhiwei_meta()

//    for(i in 0 until 27){
//        val json_str = "{\"id\":\"LOWVOL-ROOM-${30027+i+1}\",\"name\":'厚德阁2层20${i+1}房间', \"code\": \"ROOM-${getRandomString(16)}\"}"
//        println(json_str + ",")
//    }
    println()
}